import { bindPopConfig, authPopConfig } from '@/config/data.js'
import { useUserStore } from '@/stores'
//是否登录
function isLogin(){
	const token = uni.getStorageSync('token') || ''
	if (uni.$u.test.isEmpty(token)) {
		return false
	}
	return true
}
//退出登录
function logout(){
	const userStore = useUserStore()
	userStore.$reset()
	uni.removeStorageSync('token')
}
//是否绑定机具
function isBindDevice(){
	if(!isAuth()){
		return false
	}
	const userStore = useUserStore()
	//未绑定机具
	if(userStore.user.devBindStatus == '1'){
		return true
	}
	uni.$pop.show({
		type:'auth',
		config:bindPopConfig
	},(value)=>{
		//绑定终端
		uni.navigateTo({
			url:'/pages/home/bind-device/bind-device'
		})
	})
	return false
}
//是否认证
function isAuth(){
	const userStore = useUserStore()
	if (userStore.reportStatus == '1' && userStore.user.authStatus == '00') {
		//认证报备成功
		return true
	}
	else if (userStore.reportStatus == '2' || userStore.user.authStatus == '02') {
		//认证失败
		uni.$pop.show({
			type:'auth',
			config:authPopConfig
		},(value)=>{
			uni.navigateTo({
				url:`/pages/result/result?type=fail`
			})
		})
		return false
	}
	else if (userStore.reportStatus == '3' && userStore.user.authStatus == '00') {
		//报备中
		uni.$tools.showToast('报备中')
		return false
	}
	else{
		//未认证
		uni.$pop.show({
			type:'auth',
			config:authPopConfig
		},(value)=>{
			uni.navigateTo({
				url:'/pages/auth/face-auth/face-auth'
			})
		})
		return false
	}
}

export default {
	isLogin,
	logout,
	isAuth,
	isBindDevice
}